//
//  StatusRetweetCell.swift
//  sinaWeibo
//
//  Created by 张国梁 on 16/4/14.
//  Copyright © 2016年 CoderGL. All rights reserved.
//

import UIKit
import SnapKit

class StatusRetweetCell: StatusCell {
    
    override var status: Status?{
        didSet{
            // 设置转发文字
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            retweetText.text = name + ": " + text
            
            // 给图片视图传递数据
            pictureView.status = status?.retweeted_status
            
            // 布局视图尺寸
            pictureView.snp_updateConstraints { (make) in
                make.width.equalTo((status?.retweeted_status?.calculateImageSize().width)!)
                make.height.equalTo((status?.retweeted_status?.calculateImageSize().height)!)
                make.top.equalTo(retweetText.snp_bottom).offset(status?.retweeted_status?.calculateImageSize().height==0 ? 0 : margin)
            }
        }
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        contentView.addSubview(retweetText)
        contentView.insertSubview(retweetOriginal, belowSubview: pictureView)
        
        retweetText.snp_updateConstraints { (make) in
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(2 * margin)
            make.width.equalTo(width)
        }
        
        pictureView.snp_updateConstraints { (make) in
            make.top.equalTo(retweetText.snp_bottom).offset(margin)
            make.left.equalTo(retweetText)
        }
        
        
        toolBar.snp_updateConstraints { (make) in
            make.top.equalTo(pictureView.snp_bottom).offset(margin)
            make.left.right.equalTo(contentView)
            make.height.equalTo(toolBarH)
        }
        
        retweetOriginal.snp_updateConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(margin)
            make.bottom.equalTo(toolBar.snp_top)
            make.left.right.equalTo(contentView)
            
        }
    }
    
    private lazy var retweetOriginal: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.9, alpha: 0.4)
        return btn
    }()
    
    private lazy var retweetText: UILabel = {
        let label = UILabel.label(UIColor.lightGrayColor(), fontSize: 14)
        label.numberOfLines = 0
//        label.preferredMaxLayoutWidth = width
        return label
    }()
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
